import urllib.request

class Rusher(object):
  def __init__(self):
    self._NUM_TRIES = 5
    self._USER_AGENT = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)'
    self.url_list = []

  def Rush(self, proxy=None):
    for url in self.url_list:
      succeed = False
      for i in range(self._NUM_TRIES):
        if self.Request(url, proxy):
          succeed = True
          break;
      self._PrintResult(url, proxy, 'succeeds!' if succeed else 'fails......')

  def Request(self, url, proxy=None):
    pass

  def _BuildRequest(self, proxy=None):
    req = urllib.request.FancyURLopener()
    req.addheader('User-Agent', self._USER_AGENT)
    if proxy:
      req.proxies = {'http' : r'http://' + proxy + '/'}
    return req

  def _PrintResult(self, url, proxy, msg):
    if proxy:
      print('Request("%s", "%s") %s' % (url, proxy, msg))
    else:
      print('Request("%s") without proxy %s' % (url, msg))
